<?php

/**
 * 生成树形列表
 * @param $list 二维数组，至少包含 id,pid三个字段
 * @return array
 */
function generateTree($list){
    $tree = [];
    foreach ($list as &$v) {
        $pid = $v['pid'];
        if (isset($list[$pid])) {
            $list[$pid]['children'][] =$v;
        } else {
            $tree[] =$v;
        }
    }
    return $tree;
}
